<?php
/**
 * 订单类
 */
namespace Common\Model;

use Think\Model;

class TradeModel extends Model{
	
	//新增订单
	public function orderAdd($uid,$course_id,$coupon_id=""){
		
		$param['course_id']=$course_id;
		$course=M("course")->find($course_id);
		$param["course_name"]=$course['name'];
		$param["createtime"]=date("Y-m-d H:i:s",time());
		$param["uid"]=$uid;
		$param["coupon_id"]=$coupon_id;
		$coupon=D("Coupon")->getInviteCoupon($uid,$course_id);
		$param["coupon_price"]=$coupon['money'];
		$param["price"]=$course['price']-$coupon['money'];
		$param["paymoney_1"]=0;
		$param["paymoney_2"]=0;
		$param["type"]=1;
		$param['status']=0;
		$r=M("trade")->add($param);
		if($r){
			//扣除coupon
			M("coupon")->where("id='".$coupon_id."'")->save(array("status"=>1));
			return $r;
		}else{
			return false;
		}
	}
	//获取订单列表
	
	//修改订单
	
	//删除订单
	
}